home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v16n09 / partitio.asc < prev   
Encoding:
Text File  |  1991-10-10  |  4.6 KB  |  104 lines

  1. _SOFTWARE PARTITIONING FOR MULTITASKING COMMUNICATIONS_
  2. by David McCracken
  3.  
  4. [LISTING ONE]
  5.  
  6. COMMENT $ ------------------ _RELEASE --------------------------------------
  7.   A task can call this from any point to release its time. However, better 
  8. heap utilization will result from freeing memory allocated during a time slot 
  9. before releasing. To caller, release looks like a simple function whose 
  10. prototype is void release(void). All other currently enabled tasks are then
  11. dispatched in turn until the cycle is complete and this task is redispatched 
  12. by returning from the call. The si, di, ds, bp registers are restored as 
  13. expected. Thus, the release function also acts as the dispatcher. By using 
  14. "ret" to dispatch, the dispatcher automatically knows the size of 
  15. task dispatch addresses by whether SMALL or LARGE CODE.
  16. $
  17. _release    PROC
  18.     push bp
  19.     push ds
  20.     push di
  21.     push si
  22.     mov ax,dseg
  23.     mov ds,ax
  24.     mov si,[task_no] ;Get current task number.
  25.     shl si,1     ;*2 to convert to index for sp word table.
  26.     mov word ptr stk_ptrs[si],sp ;Save sp for next dispatch of this task.
  27. nextsk:    dec [task_no]
  28.     jnz dpatch     ;If task_no is OK then go dispatch the next task.
  29. ;Task 1 (on bottom of stack heap) has just finished; so verify it didn't 
  30. ; corrupt stack below allotment by checking "end of stack" marker is valid.
  31.     mov bp,mark_pos        ;Point to marker location on stack.
  32.     cmp [bp],marker_value    ;Is the mark still there?
  33.     jne scrash        ;Crash on task_no=0 means task 1 overran its stack.
  34.     mov si,[max_t_no]    
  35.     mov [task_no],si    ;Rollover task count to upper limit. 
  36. dpatch: mov si,[task_no]    ;Get current task number.
  37.     cmp byte ptr task_enable[si],0
  38.     je nextsk        ;If this task is disabled then try for next one.
  39.     shl si,1        ;*2 to convert to index for sp word table.
  40.     mov bp,mark_pos[si] ;Get this task's stack marker.
  41.     cmp [bp],marker_value   ;Did the preceding task overflow its stack?
  42.     jne scrash
  43.     cli            ;Don't allow interrupts while monkeying with stack.
  44.     mov sp,word ptr stk_ptrs[si] ;Retrieve sp saved during last dispatch 
  45.                                      ;of this task.
  46.     sti                  ;Interrupts OK now because any individual stack 
  47.                              ;should be able to support them.
  48.     pop si
  49.     pop di
  50.     pop ds
  51.     pop bp             ;Assume these registers are only ones stored through 
  52.                          ;release and re-dispatch cycle. However, watch out
  53.                          ;for possible register variables.    
  54.     ret         ;Dispatch task by returning to its release return 
  55.                          ;address. Note that dispatch/release is implicitly a 
  56.                          ;loop only by operation with dispatched tasks.
  57. _release ENDP
  58.  
  59.  
  60.  
  61. [LISTING TWO]
  62.  
  63. COMMENT $ GPIB transaction descriptors.
  64.   Each descriptor lists input destination address, maximum input length that 
  65. can be tolerated, type of response (used for concurency control), checksum 
  66. status of the response, response source address and its length.
  67. $
  68. _gpib_trans LABEL WORD                            
  69. ;  |----INPUT DESTINATION---------| |------------- RESPONSE -----------------|
  70. ;      address              length   type CHKSTAT/chkLB    address     length  
  71. ;...... analyzer status ..........| |............... acknowlege .............|
  72. dw OFFSET _status, SEG _status, 12040, 0f000h, 00fdh, OFFSET ack , SEG ack , 11
  73. ;....... command request .........| |.............. command .................|
  74.  dw      0   ,     0   ,        12, 0200h, 0100h, OFFSET _cmnd, SEG _cmnd, 245
  75. ;....... phase request ...........| |.............. command .................|
  76.  dw      0   ,     0   ,        12, 0200h, 0100h, OFFSET _cmnd, SEG _cmnd, 245
  77.                     .
  78.                     .
  79.                     .
  80.  
  81.  
  82.  
  83. [LISTING THREE]
  84.  
  85. ;-------------------- Input Available Status ----------------------
  86. _gpib_stat db 0,0,0,0  COMMENT $ _gpib_stat is defined as a 4 byte object so 
  87. that a C program can access each byte as unsigned char (UC), any pair as 
  88. unsigned short (US), or the entire group as unsigned long (UL). In C, data is 
  89. declared by "extern UC gpib". A quick check for any input would be 
  90. " if(*(UL*)gpib_stat)". Accessing as smaller objects allows catagorical 
  91. checking without having to check each bit individually. For example, 
  92. "if(*(US*)(gpib_stat+1)" tests for any bit set in the second two bytes. $
  93.  
  94. ;-------------------- Status flag selector table ---------------------
  95. flag_select   LABEL WORD        ;Flag selectors: byte selector and bit mask.
  96.         dw 0001h                ;status: flag byte 0, bit 0.
  97.         dw 0002h                ;command request: flag byte 0, bit 1.
  98.         dw 0004h                ;phase request: flag byte 0, bit 2.
  99.                     .
  100.                     .
  101.                     .
  102.  
  103.  
  104.